﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class BLL : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
           Response.ContentType = "text/plain";
    }

    public string TableName
    {
        get
        {
            return Request["TableName"];
        }
    }

    public string TableName_Emoney
    {
        get
        {
            var tbName = TableName.ToLower();
            if (tbName.EndsWith("_msn"))
            {
                return TableName.Substring(0, TableName.Length - 4);
            }
            return TableName;
        }
    }

    public List<Code.DAL.Table> CurrentDables
    {
        get
        {
            return (List<Code.DAL.Table>)Session["Tables"];
        }
    }

    public Code.DAL.Table CurrentTable
    {
        get
        {
            return CurrentDables.Find(x => x.Name == TableName);
        }
    }

    public string TableDesc
    {
        get
        {
            return CurrentTable.Desc;
        }
    }

    public string Ps
    {
        get
        {
            var columns = CurrentTable.Columns;
            string str = "";
            for (int i = 0; i < columns.Count; i++)
            {
                var c = columns[i];
                if (c.IsKey)
                {
                    var name = c.Name;
                    name = name.Substring(0, 1).ToUpper() + name.Substring(1);
                    str +=  "c." + name + ",";
                }
            }
            if (str.Length > 0)
            {
                str = str.Substring(0, str.Length - 1);
            }
            return str;
        }
    }
}